# THIS SCRIPT CODES AND CLEANS DATA FROM THE ANES CUMULATIVE FILE. IT NEEDS TO BE 
# USED IN CONJUNCTION WITH THE FILE (AVAILABLE ON DATAVERSE) ENTITLED "ANESCumulativeFile.dta"
library(foreign)
library(car)
library(readstata13)
library(ggplot2)
library(stargazer)
library(grid)
library(gridExtra)
library(survey)
library(dplyr)
library(lemon)
library(ggpubr)
library(reshape2)
#-----
# READ IN THE DATA. SELECT THE FILE "ANESCumulativeFile.dta"
our.data = read.dta13(file.choose(), nonint.factors = TRUE,
                      generate.factors = TRUE)
#------
# YEAR
our.data$year = our.data$VCF0004
table(our.data$year)

# FEELING THERMOMETER, REPUBLICAN PARTY.
# table(our.data$VCF0224)
# levels(our.data$VCF0224)
# our.data$repFT = our.data$VCF0224
# levels(our.data$repFT)[c(96:98)] = c("100", "Refused", "Dont Know")
# levels(our.data$repFT)
# our.data$repFT = car::recode(our.data$repFT, "'Refused' = NA;
#                             'Dont Know' = NA")
# our.data$repFT = as.numeric(as.character(our.data$repFT))
# table(our.data$repFT, our.data$VCF0224)
# table(our.data$repFT)

# FEELING THERMOMETER, DEMOCRATIC PARTY.
# table(our.data$VCF0218)
# levels(our.data$VCF0218)
# our.data$demFT = our.data$VCF0218
# levels(our.data$demFT)[c(97:99)] = c("100", "Refused", "Dont Know")
# levels(our.data$demFT)
# our.data$demFT = car::recode(our.data$demFT, "'Refused' = NA;
#                             'Dont Know' = NA")
# our.data$demFT = as.numeric(as.character(our.data$demFT))
# table(our.data$demFT)
# table(our.data$VCF0218)

# DIFFERENCE, REPUBLICAN FT - DEMOCRATIC FT 
# our.data$repversusdemdiff_therm = our.data$repFT - our.data$demFT
# summary(our.data$repversusdemdiff_therm)
# our.data$repversusdemdiff_therm = scales::rescale(our.data$repversusdemdiff_therm)
# table(our.data$repversusdemdiff_therm)

# PARTY ID
table(our.data$VCF0301)
our.data$partyID = as.numeric(our.data$VCF0301)
table(our.data$partyID)
our.data$partyID = car::recode(our.data$partyID, "1 = NA")
our.data$partyID = our.data$partyID - 2
table(our.data$partyID, our.data$VCF0301)
# 0 = STRONG DEMOCRAT; 6 = STRONG REPUBLICAN

# REPUBLICAN
our.data$republican = ifelse(our.data$partyID>=4 & our.data$partyID<=6, 1, 0)
table(our.data$republican, our.data$VCF0301)
summary(our.data$republican)

# DEMOCRAT 
our.data$democrat = ifelse(our.data$partyID>=0 & our.data$partyID<=2, 1, 0)
table(our.data$democrat)
table(our.data$democrat, our.data$VCF0301)

# PARTY IDENTIFICATION (THREE-CATEGORY)
table(our.data$partyID)
our.data$parties3 = car::recode(our.data$partyID, "0 = 'Democrat'; 1 = 'Democrat'; 2 = 'Democrat'; 
                                3 = 'Independent'; 4 = 'Republican'; 5 = 'Republican'; 6 = 'Republican';
                                else = NA")
table(our.data$parties3, our.data$partyID)

# IDEOLOGICAL SELF-IDENTIFICATION
table(our.data$VCF0803)
our.data$ideology = as.numeric(our.data$VCF0803)
table(our.data$ideology)
our.data$ideology = car::recode(our.data$ideology, "9 = 5; 1 = NA")
table(our.data$ideology)
our.data$ideology = our.data$ideology - 2
table(our.data$ideology, our.data$VCF0803)
table(our.data$VCF0803, our.data$year)
# 0 = EXTREMELY LIBERAL; 6 = EXTREMELY CONSERVATIVE; 
# DK OR HTMA CODED AT MIDPOINT. 

# CONSERVATIVE 
our.data$conservative = ifelse(our.data$ideology>=4 & our.data$ideology<=6, 1, 0)
table(our.data$conservative, our.data$VCF0803)
summary(our.data$conservative)

# LIBERAL
our.data$liberal = ifelse(our.data$ideology>=0 & our.data$ideology<=2, 1, 0)
table(our.data$liberal, our.data$VCF0803)
summary(our.data$liberal)

# SORTED
our.data$sorted = rep(0, length(our.data$ideology))
our.data$sorted[our.data$republican==1 & our.data$conservative==1] = 1
table(our.data$sorted)
our.data$sorted[our.data$democrat==1 & our.data$liberal==1] = 1
table(our.data$sorted)
our.data$sorted[is.na(our.data$partyID)=="TRUE" | is.na(our.data$ideology)=="TRUE"] = NA
table(our.data$sorted)
our.data$sorted[our.data$partyID==3] = 0
table(our.data$sorted)
summary(our.data$sorted)
table(our.data$sorted[our.data$republican==1], our.data$VCF0803[our.data$republican==1])
table(our.data$sorted[our.data$democrat==1], our.data$VCF0803[our.data$democrat==1])
table(our.data$sorted, our.data$partyID)
# 1 = CONSERVATIVE REPUBLICAN OR LIBERAL DEMOCRAT (SELF-IDENTIFIED); 0 = ALL OTHERS

# IDEOLOGICAL PLACEMENT, DEMOCRATIC PARTY
table(our.data$VCF0503)
our.data$demplacement = as.numeric(our.data$VCF0503)
table(our.data$demplacement)
our.data$demplacement = car::recode(our.data$demplacement, "1 = NA; 9 = NA")
our.data$demplacement = our.data$demplacement - 2
table(our.data$demplacement, our.data$VCF0503)
# 0 = EXTREMELY LIBERAL; 6 = EXTREMELY CONSERVATIVE 

# IDEOLOGICAL PLACEMENT, REPUBLICAN PARTY 
table(our.data$VCF0504)
our.data$GOPplacement = as.numeric(our.data$VCF0504)
table(our.data$GOPplacement)
our.data$GOPplacement = car::recode(our.data$GOPplacement, "1 = NA; 9 = NA")
our.data$GOPplacement = our.data$GOPplacement - 2
table(our.data$GOPplacement, our.data$VCF0504)
# 0 = EXTREMELY LIBERAL; 6 = EXTREMELY CONSERVATIVE

# DIFFERENCE BETWEEN PARTIES
our.data$partydifference = our.data$GOPplacement - our.data$demplacement
table(our.data$partydifference)

# KNOWS PARTIES' POLICY REPUTATIONS
our.data$knowsreputations = ifelse((our.data$GOPplacement > our.data$demplacement) & 
                                     (our.data$GOPplacement>=0 & our.data$GOPplacement<=6) & 
                                     (our.data$demplacement>=0 & our.data$demplacement<=6), 1, 0)
table(our.data$knowsreputations)
# DKs CODED AS NOT KNOWING POLICY REPUTATIONS
our.data$knowsreputations[our.data$VCF0504=="8. DK party placement"] = 0
table(our.data$knowsreputations)
our.data$knowsreputations[our.data$VCF0503=="8. DK party placement"] = 0
table(our.data$knowsreputations)
table(our.data$partydifference, our.data$knowsreputations)
# 0 = DOESN'T KNOW THAT THE REPUBLICAN PARTY IS MORE CONSERVATIVE THAN THE DEMOCRATIC PARTY;
# 1 = KNOWS THAT THE REPUBLICAN PARTY IS MORE CONSERVATIVE THAN THE DEMOCRATIC PARTY. 

# PROGRAMMATIC INDEX
our.data$programmatic = rep(NA, length(our.data$ideology))
# NOT MATCHED
our.data$programmatic[our.data$sorted==0 & our.data$knowsreputations==0] = 0
table(our.data$programmatic)
# PARTIALLY MATCHED
our.data$programmatic[our.data$sorted==1 & our.data$knowsreputations==0] = 0.5
table(our.data$programmatic)
our.data$programmatic[our.data$sorted==0 & our.data$knowsreputations==1] = 0.5
table(our.data$programmatic)
# MATCHED
our.data$programmatic[our.data$sorted==1 & our.data$knowsreputations==1] = 1
table(our.data$programmatic)
summary(our.data$programmatic)
# CODE AS UNMATCHED PEOPLE THAT SAID 'DK' TO VCF0803 AND THUS WEREN'T ASKED THE PARTY PLACEMENT QUESTIONS
our.data$programmatic[our.data$VCF0803=="9. DK; haven't thought much about it" & 
                        our.data$VCF0504=="0. NA party placement; DK/NA self-placement (1984-1996);"] = 0
table(our.data$programmatic)
table(our.data$programmatic, our.data$year)
# 1 = MATCHED; 0.5 = PARTIALLY MATCHED; 0 = UNMATCHED 

# FEDERAL SPENDING, CHILDCARE 
table(our.data$VCF0887)
our.data$pm_childcare = as.numeric(our.data$VCF0887)
our.data$pm_childcare = car::recode(our.data$pm_childcare, "1 = 1; 2 = 1; 3 = 0; 4 = 0; 5 = NA")
table(our.data$pm_childcare, our.data$VCF0887)
# 1 = INCREASED OR KEPT THE SAME; 0 = DECREASED (OR CUT OUT ENTIRELY) OR DON'T KNOW

# FEDERAL SPENDING, DEALING WITH CRIME
table(our.data$VCF0888)
our.data$pm_crime = as.numeric(our.data$VCF0888)
our.data$pm_crime = car::recode(our.data$pm_crime, "1 = 1; 2 = 1; 3 = 0; 4 = 0; 5 = NA")
table(our.data$pm_crime, our.data$VCF0888)
# 1 = INCREASED OR KEPT THE SAME; 0 = DECREASED (OR CUT OUT ENTIRELY) OR DON'T KNOW

# FEDERAL SPENDING, SOCIAL SECURITY
table(our.data$VCF9049)
our.data$pm_ss = as.numeric(our.data$VCF9049)
our.data$pm_ss = car::recode(our.data$pm_ss, "1 = 1; 2 = 1; 3 = 0; 4 = 0; 5 = 0; 6 = NA")
table(our.data$pm_ss, our.data$VCF9049)
# 1 = INCREASED OR KEPT THE SAME; 0 = DECREASED (OR CUT OUT ENTIRELY) OR DON'T KNOW

# AFFIRMATIVE ACTION IN HIRING/PROMOTION
table(our.data$VCF0867a)
our.data$affirmativeaction = as.numeric(our.data$VCF0867a)
table(our.data$affirmativeaction)
our.data$affirmativeaction = car::recode(our.data$affirmativeaction, "5 = NA;
                                         6 = NA; 7 = NA")
our.data$affirmativeaction = scales::rescale(our.data$affirmativeaction)
table(our.data$affirmativeaction, our.data$VCF0867a)
# 0-3 SCALE, 0 = FAVOR STRONGLY; 1 = FAVOR NOT STRONGLY; 
# 2 = OPPOSE NOT STRONGLY; 3 = OPPOSE STRONGLY 

# AFFIRMATIVE ACTION: CONSERVATIVE OR LIBERAL RESPONSE  
table(our.data$affirmativeaction)
table(as.numeric(as.factor(our.data$affirmativeaction)))
our.data$affirmativeaction_LC = car::recode(as.numeric(as.factor(our.data$affirmativeaction)), 
"1 = 'Liberal'; 2 = 'Liberal'; 3 = 'Conservative'; 4 = 'Conservative'")
table(our.data$affirmativeaction_LC, our.data$VCF0867a)
# "FAVOR STRONGLY" AND "FAVOR NOT STRONGLY" CODED AS LIBERAL RESPONSES; 
# "OPPOSE NOT STRONGLY" AND "OPPOSE STRONGLY" CODED AS CONSERVATIVE RESPONSES 

# REPUBLICANS: MATCHED AND CONSERVATIVE ON AFFIRMATIVE ACTION
our.data$matchedGOP_affirmativeaction = ifelse(our.data$affirmativeaction_LC=="Conservative" & 
                                                 our.data$republican==1 & 
                                                 our.data$programmatic==1, 1, 0)
table(our.data$matchedGOP_affirmativeaction)
# DEMOCRATS: MATCHED AND LIBERAL ON AFFIRMATIVE ACTION
our.data$matchedDEM_affirmativeaction = ifelse(our.data$affirmativeaction_LC=="Liberal" & 
                                                 our.data$democrat==1 & 
                                                 our.data$programmatic==1, 1, 0)
table(our.data$matchedDEM_affirmativeaction)

# ABORTION
table(our.data$VCF0838)
our.data$abortion = as.numeric(our.data$VCF0838)
table(our.data$abortion)
our.data$abortion = car::recode(our.data$abortion, "1 = NA; 2 = 3; 3 = 2; 4 = 1; 5 = 0; 6 = NA")
table(our.data$abortion, our.data$VCF0838)
our.data$abortion = scales::rescale(our.data$abortion)
table(our.data$abortion, our.data$VCF0838)
# 0 = BY LAW, ABORTION SHOULD BE LEGAL AS A MATTER OF PERSONAL CHOICE; 3 = BY LAW, ABORTION SHOULD NEVER
# BE PERMITTED 

# ABORTION: CONSERVATIVE OR LIBERAL RESPONSE  
table(our.data$abortion)
table(as.numeric(as.factor(our.data$abortion)))
our.data$abortion_LC = car::recode(as.numeric(as.factor(our.data$abortion)), "1 = 'Liberal'; 
2 = 'Liberal'; 3 = 'Conservative'; 4 = 'Conservative'")
table(our.data$abortion_LC, our.data$VCF0838)
# CONSERVATIVE RESPONSES ARE THOSE THAT WOULD BAN ABORTION IN ALL OR MOST CIRCUMSTANCES;
# LIBERAL RESPONSES ARE THOSE THAT WOULD ALLOW ABORTION IN ALL OR MOST CIRCUMSTANCES

# REPUBLICANS: MATCHED AND CONSERVATIVE ON ABORTION
our.data$matchedGOP_abortion = ifelse(our.data$abortion_LC=="Conservative" & 
                                        our.data$republican==1 & 
                                        our.data$programmatic==1, 1, 0)
table(our.data$matchedGOP_abortion)
# DEMOCRATS: MATCHED AND LIBERAL ON ABORTION
our.data$matchedDEM_abortion = ifelse(our.data$abortion_LC=="Liberal" & 
                                        our.data$democrat==1 & 
                                        our.data$programmatic==1, 1, 0)
table(our.data$matchedDEM_abortion)

# SEVEN-POINT SCALE: GOVERNMENT SERVICES AND SPENDING
table(our.data$VCF0839)
our.data$govspending = as.numeric(our.data$VCF0839)
table(our.data$govspending)
our.data$govspending = car::recode(our.data$govspending, "9 = 5; 1 = NA")
our.data$govspending = our.data$govspending - 2
our.data$govspending = abs(our.data$govspending - 6)
our.data$govspending = scales::rescale(our.data$govspending)
table(our.data$govspending, our.data$VCF0839)
# 0-6 SCALE, 0 = GOVERNMENT SHOULD PROVIDE MANY MORE SERVICES; 6 = GOVERNMENT SHOULD PROVIDE
# MANY FEWER SERVICES. 'HAVEN'T THOUGHT MUCH ABOUT THIS' CODED AT THE MIDPOINT. 

# GOVERNMENT SPENDING AND SERVICES: CONSERVATIVE OR LIBERAL RESPONSE  
table(our.data$govspending)
table(as.numeric(as.factor(our.data$govspending)))
our.data$govspending_LC = car::recode(as.numeric(as.factor(our.data$govspending)), "1 = 'Liberal'; 
2 = 'Liberal'; 3 = 'Liberal'; 4 = 'Moderate'; 5 = 'Conservative'; 6 = 'Conservative'; 7 = 'Conservative'")
table(our.data$govspending_LC, our.data$VCF0839)
# CONSERVATIVE RESPONSES WERE CHOICES 5, 6, OR 7 ON THE REVERSE-CODED SCALE;
# LIBERAL RESPONSES WERE CHOICES 1, 2, OR 3 ON THE REVERSE-CODED SCALE.

# REPUBLICANS: MATCHDED AND CONSERVATIVE ON GOVERNMENT SERVICES AND SPENDING
our.data$matchedGOP_govspending = ifelse(our.data$govspending_LC=="Conservative" & 
                                           our.data$republican==1 & 
                                           our.data$programmatic==1, 1, 0)
table(our.data$matchedGOP_govspending)
# DEMOCRATS: MATCHED AND LIBERAL ON GOVERNMENT SERVICES AND SPENDING
our.data$matchedDEM_govspending = ifelse(our.data$govspending_LC=="Liberal" & 
                                           our.data$democrat==1 & 
                                           our.data$programmatic==1, 1, 0)
table(our.data$matchedDEM_govspending)

# SEVEN-POINT SCALE: GOVERNMENT HEALTHCARE
table(our.data$VCF0806)
our.data$govhealth = as.numeric(our.data$VCF0806)
table(our.data$govhealth)
our.data$govhealth = car::recode(our.data$govhealth, "9 = 5; 1 = NA")
our.data$govhealth = our.data$govhealth - 2
our.data$govhealth = scales::rescale(our.data$govhealth)
table(our.data$govhealth, our.data$VCF0806)
# 0-TO-6 SCALE; 0 = GOVERNMENT-RUN HEALTH INSURANCE; 6 = PRIVATE INSURANCE
# 'HAVEN'T THOUGHT MUCH ABOUT THIS' CODED AT THE MIDPOINT. 

# GOVERNMENT HEALTH INSURANCE: CONSERVATIVE OR LIBERAL RESPONSE  
table(our.data$govhealth)
table(as.numeric(as.factor(our.data$govhealth)))
our.data$govhealth_LC = car::recode(as.numeric(as.factor(our.data$govhealth)), "1 = 'Liberal'; 
2 = 'Liberal'; 3 = 'Liberal'; 4 = 'Moderate'; 5 = 'Conservative'; 6 = 'Conservative'; 7 = 'Conservative'")
table(our.data$govhealth_LC, our.data$VCF0806)
# CONSERVATIVE RESPONSES WERE CHOICES 5, 6, OR 7 THE ORIGINAL SCALE; 
# LIBERAL RESPONSES WERE CHOICES 1, 2, OR 3 ON THE ORIGINAL SCALE. 

# REPUBLICANS: MATCHED AND CONSERVATIVE ON GOVERNMENT HEALTH INSURANCE
our.data$matchedGOP_govhealth = ifelse(our.data$govhealth_LC=="Conservative" & 
                                         our.data$republican==1 & 
                                         our.data$programmatic==1, 1, 0)
table(our.data$matchedGOP_govhealth)
# DEMOCRATS: MATCHED AND LIBERAL ON GOVERNMENT HEALTH INSURANCE
our.data$matchedDEM_govhealth = ifelse(our.data$govhealth_LC=="Liberal" & 
                                         our.data$democrat==1 & 
                                         our.data$programmatic==1, 1, 0)
table(our.data$matchedDEM_govhealth)

# SEVEN-POINT SCALE: GOVERNMENT GUARANTEED JOBS 
table(our.data$VCF0809)
our.data$govjobs = as.numeric(our.data$VCF0809)
table(our.data$govjobs)
our.data$govjobs = car::recode(our.data$govjobs, "9 = 5; 1 = NA")
our.data$govjobs = our.data$govjobs - 2
our.data$govjobs = scales::rescale(our.data$govjobs)
table(our.data$govjobs, our.data$VCF0809)
# 0-TO-6 SCALE, 0 = GOVERNMENT SHOULD SEE TO JOBS AND GOOD STANDARD OR LIVING; 6 = 
# GOVERNMENT SHOULD LET EACH GET AHEAD ON OWN 

# GOVERNMENT GUARANTEED JOBS: CONSERVATIVE OR LIBERAL RESPONSE  
table(our.data$govjobs)
table(as.numeric(as.factor(our.data$govjobs)))
our.data$govjobs_LC = car::recode(as.numeric(as.factor(our.data$govjobs)), "1 = 'Liberal'; 
2 = 'Liberal'; 3 = 'Liberal'; 4 = 'Moderate'; 5 = 'Conservative'; 6 = 'Conservative'; 7 = 'Conservative'")
table(our.data$govjobs_LC, our.data$VCF0809)
# CONSERVATIVE RESPONSES WERE CHOICES 5, 6, OR 7 THE ORIGINAL SCALE; 
# LIBERAL RESPONSES WERE CHOICES 1, 2, OR 3 ON THE ORIGINAL SCALE. 

# REPUBLICANS: MATCHED AND CONSERVATIVE ON GOVERNMENT GUARANTEED JOBS 
our.data$matchedGOP_govjobs = ifelse(our.data$govjobs_LC=="Conservative" & 
                                       our.data$republican==1 & 
                                       our.data$programmatic==1, 1, 0)
table(our.data$matchedGOP_govjobs)
# DEMOCRATS: MATCHED AND LIBERAL ON GOVERNMENT GUARANTEED JOBS 
our.data$matchedDEM_govjobs = ifelse(our.data$govjobs_LC=="Liberal" & 
                                       our.data$democrat==1 & 
                                       our.data$programmatic==1, 1, 0)
table(our.data$matchedDEM_govjobs)

# ADDITIVE INDEX: GOVERNMENT CONSERVATISM
our.data$govconservatism = (our.data$govjobs + our.data$govhealth + our.data$govspending)/3
table(our.data$govconservatism)
our.data$govconservatism = scales::rescale(our.data$govconservatism)
table(our.data$govconservatism)

# SEVEN-POINT SCALE: GOVERNMENT AID TO BLACKS
table(our.data$VCF0830)
our.data$aidblacks = as.numeric(our.data$VCF0830)
table(our.data$aidblacks)
our.data$aidblacks = car::recode(our.data$aidblacks, "9 = 5; 1 = NA")
our.data$aidblacks = our.data$aidblacks - 2
our.data$aidblacks = scales::rescale(our.data$aidblacks)
table(our.data$aidblacks, our.data$VCF0830)
# 0-TO-6 SCALE, 0 = GOVERNMENT SHOULD HELP BLACKS; 
# 6 = BLACKS SHOULD HELP THEMSELVES

# GOVERNMENT AID TO BLACKS: CONSERVATIVE OR LIBERAL RESPONSE  
table(our.data$aidblacks)
table(as.numeric(as.factor(our.data$aidblacks)))
our.data$aidblacks_LC = car::recode(as.numeric(as.factor(our.data$aidblacks)), "1 = 'Liberal'; 
2 = 'Liberal'; 3 = 'Liberal'; 4 = 'Moderate'; 5 = 'Conservative'; 6 = 'Conservative'; 7 = 'Conservative'")
table(our.data$aidblacks_LC, our.data$VCF0830)
# CONSERVATIVE RESPONSES WERE CHOICES 5, 6, OR 7 THE ORIGINAL SCALE; 
# LIBERAL RESPONSES WERE CHOICES 1, 2, OR 3 ON THE ORIGINAL SCALE. 

# REPUBLICANS: MATCHED AND CONSERVATIVE ON GOVERNMENT AID TO BLACKS
our.data$matchedGOP_aidblacks = ifelse(our.data$aidblacks_LC=="Conservative" & 
                                         our.data$republican==1 & 
                                         our.data$programmatic==1, 1, 0)
table(our.data$matchedGOP_aidblacks)
# DEMOCRATS: MATCHED AND LIBERAL ON GOVERNMENT AID TO BLACKS 
our.data$matchedDEM_aidblacks = ifelse(our.data$aidblacks_LC=="Liberal" & 
                                         our.data$democrat==1 & 
                                         our.data$programmatic==1, 1, 0)
table(our.data$matchedDEM_aidblacks)

# MORAL TRADITIONALISM #1: "THE NEWER LIFESTYLES ARE CONTRIBUTING TO THE 
# BREAKDOWN OF SOCIETY." 
table(our.data$VCF0851)
our.data$cultural_newlifestyles = as.numeric(our.data$VCF0851)
table(our.data$cultural_newlifestyles)
our.data$cultural_newlifestyles = car::recode(our.data$cultural_newlifestyles, "6 = 3; 7 = NA") - 1
our.data$cultural_newlifestyles = abs(4 - our.data$cultural_newlifestyles)
table(our.data$cultural_newlifestyles, our.data$VCF0851)
# 0-TO-4 SCALE, 0 = DISAGREE STRONGLY; 2 = NEITHER AGREE NOR DISAGREE; 4 = AGREE STRONGLY. 
# DK CODED AS 'NEITHER AGREE NOR DISAGREE'

# MORAL TRADITIONALISM #1: "THE NEWER LIFESTYLES ARE CONTRIBUTING TO THE 
# BREAKDOWN OF SOCIETY," CONSERVATIVE OR LIBERAL RESPONSE 
table(our.data$cultural_newlifestyles)
our.data$cultural_newlifestyles_LC = car::recode(our.data$cultural_newlifestyles, "0 = 'Liberal'; 
1 = 'Liberal'; 2 = 'Moderate'; 3 = 'Conservative';  4 = 'Conservative'")
table(our.data$cultural_newlifestyles_LC, our.data$VCF0851)
# CONSERVATIVE RESPONSES ARE THOSE THAT AGREED STRONGLY OR NOT STRONGLY THAT 
# THE NEWER LIFESTYLES ARE CONTRIBUTING TO THE BREAKDOWN OF SOCIETY.
# LIBERAL RESPONSES ARE THOSE THAT DISAGREED STRONGLY OR NOT STRONGLY THAT 
# THE NEWER LIFESTYLES ARE CONTRIBUTING TO THE BREAKDOWN OF SOCIETY.

# REPUBLICANS: MATCHED AND CONSERVATIVE ON THE "NEW LIFESTYLES" QUESTION
our.data$matchedGOP_MTnewlifestyles = ifelse(our.data$cultural_newlifestyles_LC=="Conservative" & 
                                               our.data$republican==1 & 
                                               our.data$programmatic==1, 1, 0)
table(our.data$matchedGOP_MTnewlifestyles)
# DEMOCRATS: MATCHED AND LIBERAL ON THE "NEW LIFESTYLES" QUESTION 
our.data$matchedDEM_MTnewlifestyles = ifelse(our.data$cultural_newlifestyles_LC=="Liberal" & 
                                               our.data$democrat==1 & 
                                               our.data$programmatic==1, 1, 0)
table(our.data$matchedDEM_MTnewlifestyles)

# MORAL TRADITIONALISM #2: "THE WORLD IS ALWAYS CHANGING AND WE SHOULD ADJUST 
# OUR VIEW OF MORAL BEHAVIOR TO THESE CHANGES." 
table(our.data$VCF0852)
our.data$cultural_adjustviews = as.numeric(our.data$VCF0852)
table(our.data$cultural_adjustviews)
our.data$cultural_adjustviews = car::recode(our.data$cultural_adjustviews, "6 = 3; 7 = NA") - 1
table(our.data$cultural_adjustviews, our.data$VCF0852)
# 0-TO-4 SCALE, 0 = AGREE STRONGLY; 2 = NEITHER AGREE NOR DISAGREE; 
# 4 = DISAGREE STRONGLY. DK CODED AS 'NEITHER AGREE NOR DISAGREE'

# MORAL TRADITIONALISM #2: "THE WORLD IS ALWAYS CHANGING AND WE SHOULD ADJUST 
# OUR VIEW OF MORAL BEHAVIOR TO THESE CHANGES," CONSERVATIVE OR LIBERAL RESPONSE 
table(our.data$cultural_adjustviews)
our.data$cultural_adjustviews_LC = car::recode(our.data$cultural_adjustviews, "0 = 'Liberal'; 
1 = 'Liberal'; 2 = 'Moderate'; 3 = 'Conservative';  4 = 'Conservative'")
table(our.data$cultural_adjustviews_LC, our.data$VCF0852)
# CONSERVATIVE RESPONSES ARE THOSE THAT DISAGREED STRONGLY OR NOT STRONGLY THAT 
# WE SHOULD ADJUST OUR VIEW OF MORAL BEHAVIOR. 
# LIBERAL RESPONSES ARE THOSE THAT AGREED STRONGLY OR NOT STRONGLY THAT 
# WE SHOULD ADJUST OUR VIEW OF MORAL BEHAVIOR. 

# REPUBLICANS: MATCHED AND CONSERVATIVE ON THE "ADJUST MORAL VIEWS" QUESTION
our.data$matchedGOP_MTadjustviews = ifelse(our.data$cultural_adjustviews_LC=="Conservative" & 
                                             our.data$republican==1 & 
                                             our.data$programmatic==1, 1, 0)
table(our.data$matchedGOP_MTadjustviews)
# DEMOCRATS: MATCHED AND LIBERAL ON THE "ADJUST MORAL VIEWS" QUESTION
our.data$matchedDEM_MTadjustviews = ifelse(our.data$cultural_adjustviews_LC=="Liberal" & 
                                             our.data$democrat==1 & 
                                             our.data$programmatic==1, 1, 0)
table(our.data$matchedDEM_MTadjustviews)

# MORAL TRADITIONALISM #3: "THIS COUNTRY WOULD HAVE MANY FEWER PROBLEMS IF 
# THERE WERE MORE EMPHASIS ON TRADITIONAL FAMILY TIES." 
table(our.data$VCF0853)
our.data$cultural_traditionalvalues = as.numeric(our.data$VCF0853)
table(our.data$cultural_traditionalvalues)
our.data$cultural_traditionalvalues = car::recode(our.data$cultural_traditionalvalues, 
                                                  "6 = 3; 7 = NA") - 1
our.data$cultural_traditionalvalues = abs(4 - our.data$cultural_traditionalvalues)
table(our.data$cultural_traditionalvalues, our.data$VCF0853)
# 0-TO-4 SCALE, 0 = DISAGREE STRONGLY; 2 = NEITHER AGREE NOR DISAGREE; 
# 4 = AGREE STRONGLY. DK CODED AS 'NEITHER AGREE NOR DISAGREE'

# MORAL TRADITIONALISM #3: "THIS COUNTRY WOULD HAVE MANY FEWER PROBLEMS IF THERE WERE 
# MORE EMPHASIS ON TRADITIONAL FAMILY TIES," CONSERVATIVE OR LIBERAL RESPONSE. 
table(our.data$cultural_traditionalvalues)
our.data$cultural_traditionalvalues_LC = car::recode(our.data$cultural_traditionalvalues, "0 = 'Liberal'; 
1 = 'Liberal'; 2 = 'Moderate'; 3 = 'Conservative';  4 = 'Conservative'")
table(our.data$cultural_traditionalvalues_LC, our.data$VCF0853)
# CONSERVATIVE RESPONSES ARE THOSE THAT AGREED STRONGLY OR NOT STRONGLY THAT 
# THE COUNTRY WOULD HAVE FEWER PROBLEMS IF THERE WERE MORE EMPHASIS ON TRADITIONAL FAMILY TIES.
# LIBERAL RESPONSES ARE THOSE THAT DISAGREED STRONGLY OR NOT STRONGLY THAT 
# THE COUNTRY WOULD HAVE FEWER PROBLEMS IF THERE WERE MORE EMPHASIS ON TRADITIONAL FAMILY TIES. 

# REPUBLICANS: MATCHED AND CONSERVATIVE ON THE "TRADITIONAL VALUES" QUESTION
our.data$matchedGOP_MTtraditionalvalues = ifelse(our.data$cultural_traditionalvalues_LC=="Conservative" & 
                                                   our.data$republican==1 & 
                                                   our.data$programmatic==1, 1, 0)
table(our.data$matchedGOP_MTtraditionalvalues)
# DEMOCRATS: MATCHED AND LIBERAL ON THE "TRADITIONAL VALUES" QUESTION
our.data$matchedDEM_MTtraditionalvalues = ifelse(our.data$cultural_traditionalvalues_LC=="Liberal" & 
                                                   our.data$democrat==1 & 
                                                   our.data$programmatic==1, 1, 0)
table(our.data$matchedDEM_MTtraditionalvalues)

# MORAL TRADITIONALISM #4: "WE SHOULD BE MORE TOLERANT OF THOSE WITH DIFFERENT MORAL STANDARDS,
# EVEN IF THESE ARE VERY DIFFERENT FROM OUR OWN." 
table(our.data$VCF0854)
our.data$cultural_toleratenew = as.numeric(our.data$VCF0854)
table(our.data$cultural_toleratenew)
our.data$cultural_toleratenew = car::recode(our.data$cultural_toleratenew, "6 = 3; 7 = NA") - 1
table(our.data$cultural_toleratenew, our.data$VCF0854)
# 0-TO-4 SCALE, 0 = AGREE STRONGLY; 2 = NEITHER AGREE NOR DISAGREE; 4 = DISAGREE STRONGLY. 
# DK CODED AS 'NEITHER AGREE NOR DISAGREE'

# MORAL TRADITIONALISM #4: "WE SHOULD BE MORE TOLERANT OF THOSE WITH DIFFERENT MORAL STANDARDS,
# EVEN IF THESE ARE VERY DIFFERENT FROM OUR OWN," CONSERVATIVE OR LIBERAL RESPONSE  
table(our.data$cultural_toleratenew)
our.data$cultural_toleratenew_LC = car::recode(our.data$cultural_toleratenew, "0 = 'Liberal'; 
                                               1 = 'Liberal'; 2 = 'Moderate'; 3 = 'Conservative'; 
                                               4 = 'Conservative'")
table(our.data$cultural_toleratenew_LC, our.data$VCF0854)
# CONSERVATIVE RESPONSES ARE THOSE THAT DISAGREED STRONGLY OR NOT STRONGLY THAT 
# WE SHOULD BE MORE TOLERANT OF PEOPLE WITH DIFFERENT MORAL STANDARDS. 
# LIBERAL RESPONSES ARE THOSE THAT AGREED STRONGLY OR NOT STRONGLY THAT 
# WE SHOULD BE MORE TOLERANT OF PEOPLE WITH DIFFERENT MORAL STANDARDS. 

# REPUBLICANS: MATCHED AND CONSERVATIVE ON THE "TOLERATE DIFFERENT MORAL STANDARDS" QUESTION
our.data$matchedGOP_MTtoleratenew = ifelse(our.data$cultural_toleratenew_LC=="Conservative" & 
                                             our.data$republican==1 & 
                                             our.data$programmatic==1, 1, 0)
table(our.data$matchedGOP_MTtoleratenew)
# DEMOCRATS: MATCHED AND LIBERAL ON THE "TOLERATE DIFFERENT MORAL STANDARDS" QUESTION
our.data$matchedDEM_MTtoleratenew = ifelse(our.data$cultural_toleratenew_LC=="Liberal" & 
                                             our.data$democrat==1 & 
                                             our.data$programmatic==1, 1, 0)
table(our.data$matchedGOP_MTtoleratenew)

# MORAL TRADITIONALISM INDEX
our.data$moraltrad = our.data$cultural_adjustviews + our.data$cultural_newlifestyles + our.data$cultural_toleratenew + 
  our.data$cultural_traditionalvalues
table(our.data$moraltrad, our.data$VCF0004)
our.data$moraltrad = scales::rescale(our.data$moraltrad)

# WHITE, NON-HISPANIC 
table(our.data$VCF0105a)
our.data$whiteNH = as.numeric(our.data$VCF0105a)
table(our.data$whiteNH)
our.data$whiteNH = ifelse(our.data$whiteNH==1, 1, 0)
table(our.data$whiteNH, our.data$VCF0105a)
# 1 = NON-HISPANIC WHITES; 0 = OTHERS (INCLUDING THOSE FOR WHOM DATA ARE MISSING)

# RACIAL RESENTMENT #1: "GENERATIONS OF SLAVERY AND DISCRIMINATION HAVE CREATED CONDITIONS 
# THAT MAKE IT DIFFICULT FOR BLACKS TO WORK THEIR WAY OUT OF THE LOWER CLASSES."
table(our.data$VCF9039)
our.data$rr_difficultsucceed = as.numeric(our.data$VCF9039)
table(our.data$rr_difficultsucceed)
our.data$rr_difficultsucceed = car::recode(our.data$rr_difficultsucceed, "6 = 3; 7 = NA") - 1
table(our.data$rr_difficultsucceed, our.data$VCF9039)
# 0-TO-4 SCALE, 0 = AGREE STRONGLY; 2 = NEITHER AGREE NOR DISAGREE; 
# 4 = DISAGREE STRONGLY. DK CODED AS 'NEITHER AGREE NOR DISAGREE'

# RACIAL RESENTMENT #1: "GENERATIONS OF SLAVERY AND DISCRIMINATION HAVE CREATED CONDITIONS 
# THAT MAKE IT DIFFICULT FOR BLACKS TO WORK THEIR WAY OUT OF THE LOWER CLASSES," 
# CONSERVATIVE OR LIBERAL RESPONSE
table(our.data$rr_difficultsucceed)
our.data$rr_difficultsucceed_LC = car::recode(our.data$rr_difficultsucceed, "0 = 'Liberal'; 
1 = 'Liberal'; 2 = 'Moderate'; 3 = 'Conservative';  4 = 'Conservative'")
table(our.data$rr_difficultsucceed_LC, our.data$VCF9039)
# CONSERVATIVE RESPONSES DISAGREE STRONGLY OR NOT STRONGLY THAT GENERATIONS OF SLAVERY
# AND DISCRIMINATION HAVE CREATED CONDITIONS THAT MAKE IT DIFFICULT FOR BLACKS
# TO WORK THEIR WAY OUT OF THE LOWER CLASSES. 
# LIBERAL RESPONSES *AGREE* STRONGLY OR NOT STRONGLY THAT GENERATIONS OF SLAVERY
# AND DISCRIMINATION HAVE CREATED CONDITIONS THAT MAKE IT DIFFICULT FOR BLACKS
# TO WORK THEIR WAY OUT OF THE LOWER CLASSES.  

# REPUBLICANS: MATCHED AND CONSERVATIVE ON THE "GENERATIONS OF SLAVERY" QUESTION
our.data$matchedGOP_RRdifficultsucceed = ifelse(our.data$rr_difficultsucceed_LC=="Conservative" & 
                                                  our.data$republican==1 & 
                                                  our.data$programmatic==1, 1, 0)
table(our.data$matchedGOP_RRdifficultsucceed)
# DEMOCRATS: MATCHED AND LIBERAL ON THE "GENERATIONS OF SLAVERY" QUESTION
our.data$matchedDEM_RRdifficultsucceed = ifelse(our.data$rr_difficultsucceed_LC=="Liberal" & 
                                                  our.data$democrat==1 & 
                                                  our.data$programmatic==1, 1, 0)

# RACIAL RESENTMENT #2: "IRISH, ITALIANS, JEWISH AND MANY OTHER MINORITIES OVERCAME
# PREJUDICE AND WORKED THEIR WAY UP. BLACKS SHOULD DO THE SAME WITHOUT SPECIAL FAVORS"
table(our.data$VCF9040)
our.data$rr_nofavors = as.numeric(our.data$VCF9040)
table(our.data$rr_nofavors)
our.data$rr_nofavors = car::recode(our.data$rr_nofavors, "6 = 3; 7 = NA") - 1
our.data$rr_nofavors = abs(4 - our.data$rr_nofavors)
table(our.data$rr_nofavors, our.data$VCF9040)
# 0-TO-4 SCALE, 0 = DISAGREE STRONGLY; 2 = NEITHER AGREE NOR DISAGREE; 
# 4 = AGREE STRONGLY. DK CODED AS 'NEITHER AGREE NOR DISAGREE'

# RACIAL RESENTMENT #2: "IRISH, ITALIANS, JEWISH AND MANY OTHER MINORITIES OVERCAME
# PREJUDICE AND WORKED THEIR WAY UP. BLACKS SHOULD DO THE SAME WITHOUT SPECIAL FAVORS"
# CONSERVATIVE OR LIBERAL RESPONSE
table(our.data$rr_nofavors)
our.data$rr_nofavors_LC = car::recode(our.data$rr_nofavors, "0 = 'Liberal'; 
1 = 'Liberal'; 2 = 'Moderate'; 3 = 'Conservative';  4 = 'Conservative'")
table(our.data$rr_nofavors_LC, our.data$VCF9040)
# CONSERVATIVE RESPONSES *AGREE* STRONGLY OR NOT STRONGLY THAT BLACKS SHOULD 
# DO THE SAME WITHOUT SPECIAL FAVORS. 
# LIBERAL RESPONSES *DISAGREE* STRONGLY OR NOT STRONGLY THAT BLACKS SHOULD 
# DO THE SAME WITHOUT SPECIAL FAVORS

# REPUBLICANS: MATCHED AND CONSERVATIVE ON THE "IRISH, ITALIANS, AND JEWISH" QUESTION
our.data$matchedGOP_RRnofavors = ifelse(our.data$rr_nofavors_LC=="Conservative" & 
                                          our.data$republican==1 & 
                                          our.data$programmatic==1, 1, 0)
table(our.data$matchedGOP_RRnofavors)
# DEMOCRATS: MATCHED AND LIBERAL ON THE "IRISH, ITALIANS, AND JEWISH" QUESTION
our.data$matchedDEM_RRnofavors = ifelse(our.data$rr_nofavors_LC=="Liberal" & 
                                          our.data$democrat==1 & 
                                          our.data$programmatic==1, 1, 0)
table(our.data$matchedDEM_RRnofavors)

# RACIAL RESENTMENT #3: "IT'S REALLY A MATTER OF NOT TRYING HARD ENOUGH; IF BLACKS
# WOULD ONLY TRY HARDER, THEY COULD BE JUST AS WELL OFF AS WHITES." 
table(our.data$VCF9041)
our.data$rr_tryharder = as.numeric(our.data$VCF9041)
table(our.data$rr_tryharder)
our.data$rr_tryharder = car::recode(our.data$rr_tryharder, "6 = 3; 7 = NA") - 1
our.data$rr_tryharder = abs(4 - our.data$rr_tryharder)
table(our.data$rr_tryharder, our.data$VCF9041)
# 0-TO-4 SCALE, 0 = DISAGREE STRONGLY; 2 = NEITHER AGREE NOR DISAGREE;
# 4 = AGREE STRONGLY. DK CODED AS 'NEITHER AGREE NOR DISAGREE'

# RACIAL RESENTMENT #3: "IT'S REALLY A MATTER OF NOT TRYING HARD ENOUGH; IF BLACKS
# WOULD ONLY TRY HARDER, THEY COULD BE JUST AS WELL OFF AS WHITES." 
# CONSERVATIVE OR LIBERAL RESPONSE 
table(our.data$rr_tryharder)
our.data$rr_tryharder_LC = car::recode(our.data$rr_tryharder, "0 = 'Liberal'; 
1 = 'Liberal'; 2 = 'Moderate'; 3 = 'Conservative';  4 = 'Conservative'")
table(our.data$rr_tryharder_LC, our.data$VCF9041)
# CONSERVATIVE RESPONSES *AGREE* STRONGLY OR NOT STRONGLY THAT IF BLACKS WOULD 
# ONLY TRY HARDER, THEY WOULD BE JUST AS WELL-OFF AS WHITES. 
# LIBERAL RESPONSES *DISAGREE* STRONGLY OR NOT STRONGLY THAT IF BLACKS WOULD
# ONLY TRY HARDER, THEY WOULD BE JUST AS WELL-OFF AS WHITES. 

# REPUBLICANS: MATCHED AND CONSERVATIVE ON THE "TRY HARDER" QUESTION
our.data$matchedGOP_RRtryharder = ifelse(our.data$rr_tryharder_LC=="Conservative" & 
                                           our.data$republican==1 & 
                                           our.data$programmatic==1, 1, 0)
table(our.data$matchedGOP_RRtryharder)
# DEMOCRATS: MATCHED AND LIBERAL ON THE "TRY HARDER" QUESTION
our.data$matchedDEM_RRtryharder = ifelse(our.data$rr_tryharder_LC=="Liberal" & 
                                           our.data$democrat==1 & 
                                           our.data$programmatic==1, 1, 0)
table(our.data$matchedDEM_RRtryharder)

# RACIAL RESENTMENT #4: "OVER THE PAST FEW YEARS, BLACKS HAVE GOTTEN LESS THAN
# THEY DESERVE" 
table(our.data$VCF9042)
our.data$rr_lessthandeserve = as.numeric(our.data$VCF9042)
table(our.data$rr_lessthandeserve)
our.data$rr_lessthandeserve = car::recode(our.data$rr_lessthandeserve, "6 = 3; 7 = NA") - 1
table(our.data$rr_lessthandeserve, our.data$VCF9042)
# 0-TO-4 SCALE, 0 = AGREE STRONGLY; 2 = NEITHER AGREE NOR DISAGREE; 
# 4 = DISAGREE STRONGLY. DK CODED AS 'NEITHER AGREE NOR DISAGREE'

# RACIAL RESENTMENT #4: BLACKS HAVE GOTTEN LESS THAN THEY DESERVE PAST FEW YEARS
# CONSERVATIVE OR LIBERAL RESPONSE 
table(our.data$rr_lessthandeserve)
our.data$rr_lessthandeserve_LC = car::recode(our.data$rr_lessthandeserve, "0 = 'Liberal'; 
1 = 'Liberal'; 2 = 'Moderate'; 3 = 'Conservative';  4 = 'Conservative'")
table(our.data$rr_lessthandeserve_LC, our.data$VCF9042)
# CONSERVATIVE RESPONSES *DISAGREE* STRONGLY OR NOT STRONGLY THAT BLACKS HAVE
# GOTTEN LESS THAN THEY DESERVE.
# LIBERAL RESPONSES *AGREE* STRONGLY OR NOT STRONGLY THAT BLACKS HAVE
# GOTTEN LESS THAN THEY DESERVE. 

# REPUBLICANS: MATCHED AND CONSERVATIVE ON THE "LESS THAN THEY DESERVE" QUESTION
our.data$matchedGOP_RRlessthandeserve = ifelse(our.data$rr_lessthandeserve_LC=="Conservative" & 
                                                 our.data$republican==1 & 
                                                 our.data$programmatic==1, 1, 0)
table(our.data$matchedGOP_RRlessthandeserve)
# DEMOCRATS: MATCHED AND LIBERAL ON THE "LESS THAN THEY DESERVE" QUESTION
our.data$matchedDEM_RRlessthandeserve = ifelse(our.data$rr_lessthandeserve_LC=="Liberal" & 
                                                 our.data$democrat==1 & 
                                                 our.data$programmatic==1, 1, 0)
table(our.data$matchedDEM_RRlessthandeserve)

# RACIAL RESENTMENT, TOTAL
our.data$rr_total = our.data$rr_difficultsucceed + our.data$rr_lessthandeserve + 
  our.data$rr_nofavors + our.data$rr_tryharder
our.data$rr_total = scales::rescale(our.data$rr_total)
table(our.data$rr_total, our.data$year)

# GAY RIGHTS: LAW TO PROTECT HOMOSEXUALS FROM DISCRIMINATION
table(our.data$VCF0876a)
our.data$protectgays = car::recode(as.numeric(our.data$VCF0876a), "5 = NA; 6 = NA")
table(our.data$protectgays, our.data$VCF0876a)
our.data$protectgays = scales::rescale(our.data$protectgays)
our.data$protectgays = abs(1 - our.data$protectgays)
table(our.data$protectgays, our.data$VCF0876a)
# 0-TO-3 SCALE, 0 = OPPOSE STRONGLY; 1 = OPPOSE NOT STRONGLY; 
# 2 = FAVOR NOT STRONGLY; 3 = FAVOR STRONGLY

# GAY RIGHTS: ADOPTION BY SAME-SEX COUPLES 
table(our.data$VCF0878)
our.data$ssadoption = car::recode(as.numeric(our.data$VCF0878), "1 = 1; 2 = 0; 3 = 0.5; else = NA")
table(our.data$ssadoption, our.data$VCF0878)
# 1 = YES, SHOULD BE ABLE TO ADOPT; 0.5 = DON'T KNOW; 0 = NO, SHOULD NOT BE ABLE TO ADOPT

# GAY RIGHTS: GAYS IN THE MILITARY 
table(our.data$VCF0877a)
our.data$gaysmilitary = car::recode(as.numeric(our.data$VCF0877a), "5 = NA; 6 = NA") - 1
table(our.data$gaysmilitary, our.data$VCF0877a)
our.data$gaysmilitary = scales::rescale(our.data$gaysmilitary)
our.data$gaysmilitary = abs(1 - our.data$gaysmilitary)
table(our.data$gaysmilitary, our.data$VCF0877a)
# 0-TO-3 SCALE, 0 = OPPOSE STRONGLY; 1 = OPPOSE NOT STRONGLY; 
# 2 = FAVOR NOT STRONGLY; 3 = FAVOR STRONGLY 

# GUN CONTROL
table(our.data$VCF9238)
our.data$guncontrol = car::recode(as.numeric(our.data$VCF9238), 
                                  "1 = NA; 2 = 0.5; 3 = 1; 4 = 0; 5 = 0")
table(our.data$guncontrol, our.data$VCF9238)  
# 1 = MORE DIFFICULT; 0 = KEEP RULES ABOUT THE SAME *OR* MAKE IT EASIER TO BUY A GUN; 
# 0.5 = DON'T KNOW (OR DEPENDS)

# GUN CONTROL, CONSERVATIVE OR LIBERAL RESPONSE
table(our.data$guncontrol)
our.data$guncontrol_LC = car::recode(our.data$guncontrol, "0 = 'Conservative'; 
                                     0.5 = 'Moderate'; 1 = 'Liberal'; else = NA")
table(our.data$guncontrol_LC, our.data$VCF9238)
# CONSERVATIVE RESPONSES ARE 'EASIER' OR 'KEEP RULES ABOUT THE SAME'
# LIBERAL RESPONSE IS 'MORE DIFFICULT' 

# REPUBLICANS: MATCHED AND CONSERVATIVE ON GUN CONTROL 
our.data$matchedGOP_guncontrol = ifelse(our.data$guncontrol_LC=="Conservative" & 
                                          our.data$republican==1 & 
                                          our.data$programmatic==1, 1, 0)
table(our.data$matchedGOP_guncontrol)
# DEMOCRATS: MATCHED AND LIBERAL ON GUN CONTROL 
our.data$matchedDEM_guncontrol = ifelse(our.data$guncontrol_LC=="Liberal" & 
                                          our.data$democrat==1 & 
                                          our.data$programmatic==1, 1, 0)
table(our.data$matchedDEM_guncontrol)

# SOPHISTICATION: COUNT OF CAMPAIGN PARTICIPATION ACTIVITIES
table(our.data$VCF0723, our.data$year)
our.data$lla = car::recode(as.numeric(our.data$VCF0723), "1 = NA") - 2
table(our.data$lla, our.data$VCF0723)
our.data$lla = scales::rescale(our.data$lla)
table(our.data$lla, our.data$VCF0723)
# 0-TO-5 SCALE, NUMBER OF CAMPAIGN-RELATED ACTIVITIES

# POLITICAL KNOWLEDGE: PARTY WITH HOUSE MAJORITY BEFORE THE ELECTION
table(our.data$VCF0729, our.data$year)
our.data$correct_housemajority = our.data$VCF0729
our.data$correct_housemajority = car::recode(as.numeric(our.data$correct_housemajority), 
                                             "1 = NA; 2 = 0; 3 = 1")
table(our.data$correct_housemajority, our.data$VCF0729)
# 1 = CORRECT; 0 = INCORRECT 

# POLITICAL KNOWLEDGE: CORRECT IDENTIFICATION, CHIEF JUSTICE
table(our.data$VCF9262)
our.data$correct_chiefjustice = our.data$VCF9262
table(our.data$correct_chiefjustice)
our.data$correct_chiefjustice = car::recode(as.numeric(our.data$correct_chiefjustice),
                                            "1 = NA; 2 = 1; 3 = 0; else = NA")
table(our.data$correct_chiefjustice, our.data$VCF9262)
# 1 = CORRECT; 0 = INCORRECT 

# POLITICAL KNOWLEDGE: CORRECT IDENTIFICATION, SPEAKER OF THE HOUSE
our.data$correct_speaker = our.data$VCF9260
table(our.data$correct_speaker)
our.data$correct_speaker = car::recode(as.numeric(our.data$correct_speaker),
                                            "1 = NA; 2 = 1; 3 = 0; else = NA")
table(our.data$correct_speaker, our.data$VCF9260)
# 1 = CORRECT; 0 = INCORRECT 

# POLITICAL KNOWLEDGE: CORRECT IDENTIFICATION, VICE PRESIDENT
our.data$correct_VP = our.data$VCF9261
table(our.data$correct_VP)
our.data$correct_VP = car::recode(as.numeric(our.data$correct_VP),
                                       "1 = NA; 2 = 1; 3 = 0; else = NA")
table(our.data$correct_VP, our.data$VCF9261)
# 1 = CORRECT; 0 = INCORRECT 

# POLITICAL KNOWLEDGE: TOTAL SCORE
our.data$politicalknowledge = our.data$correct_chiefjustice + our.data$correct_housemajority + 
  our.data$correct_speaker + our.data$correct_VP
table(our.data$politicalknowledge, our.data$year)
our.data$politicalknowledge = scales::rescale(our.data$politicalknowledge)

# SOPHISTICATION: INTEREST IN THE ELECTIONS
table(our.data$VCF0310, our.data$year)
our.data$interest.elections = car::recode(as.numeric(our.data$VCF0310),
                                          "1 = NA; 5 = NA") - 2
table(our.data$interest.elections, our.data$VCF0310)
our.data$interest.elections = as.factor(our.data$interest.elections)
levels(our.data$interest.elections) = c("1. Not much interested", 
                                        "2. Somewhat interested",
                                        "3. Very much interested")
table(our.data$interest.elections, our.data$VCF0310)

# SOPHISTICATION: INTEREST IN PUBLIC AFFAIRS 
table(our.data$VCF0313)
our.data$interest.publicaffairs = car::recode(as.numeric(our.data$VCF0313),
                                              "1 = NA; 6 = NA")
table(our.data$interest.publicaffairs)
our.data$interest.publicaffairs = as.factor(our.data$interest.publicaffairs)
levels(our.data$interest.publicaffairs) = c("1. Hardly at all", 
                                            "2. Only now and then",
                                            "3. Some of the time",
                                            "4. Most of the time")
table(our.data$interest.publicaffairs, our.data$VCF0313)

# SOPHISTICATION: INTERVIEWER OBSERVATION, RESPONDENT LEVEL OF INFORMATION (PRE)
table(our.data$VCF0050a, our.data$year)
our.data$interviewerobs.pre = as.numeric(our.data$VCF0050a)
our.data$interviewerobs.pre = car::recode(our.data$interviewerobs.pre, "1 = 4; 
                                          2 = 3; 3 = 2; 4 = 1; 5 = 0; 6 = NA")
table(our.data$interviewerobs.pre, our.data$VCF0050a)
our.data$interviewerobs.pre = scales::rescale(our.data$interviewerobs.pre)
table(our.data$interviewerobs.pre, our.data$VCF0050a)
# 0-TO-4 SCALE, 0 = VERY LOW; 4 = VERY HIGH

# SOPHISTICATION: COLLEGE DEGREE
table(our.data$VCF0110)
our.data$hasBA = car::recode(as.numeric(our.data$VCF0110), "1 = NA; 2 = 'No BA'; 
                             3 = 'No BA'; 4 = 'No BA'; 5 = 'Has BA'; else = NA")
table(our.data$hasBA, our.data$VCF0110)

# VOTED IN GENERAL ELECTION (SELF-REPORTED)
table(our.data$VCF0703)
our.data$voted.general = car::recode(as.numeric(our.data$VCF0703), "1 = NA; 2 = 0; 3 = 0; 4 = 1; else = NA")
table(our.data$voted.general, our.data$VCF0703)
# 1 = SELF-REPORTED VOTING; 0 = NOT REGISTERED, DID NOT VOTE *OR* REGISTERED, DID NOT VOTE

# VOTED IN PRESIDENTIAL PRIMARIES AND CAUCUSES (SELF-REPORTED)
table(our.data$VCF9265)
our.data$primary.vote = car::recode(as.numeric(our.data$VCF9265), "1 = NA; 2 = NA; 3 = 1; 4 = 0; else = NA")
table(our.data$primary.vote, our.data$VCF9265)
# 1 = YES; 0 = NO

# DROP INDEPENDENTS FROM THE DATASET
new.data = subset(our.data, republican==1 | democrat==1)
#----
# SAVE DATASET 
# write.csv(new.data, file = "ANESCumulative_cleaned.csv") # WITHOUT INDEPENDENTS
# write.csv(our.data, file = "ANESCumulative_cleaned+inds.csv") # WITH INDEPENDENTS 
